/**
 * Created by clown on 2016/1/17.
 */


(function($){
	//找项目标题
	var detailHtml = $("#detail_project_title").html();
	//alert(detailHtml)
	if(!!window.sessionStorage.getItem("projectId")){
			var projectId = window.sessionStorage.getItem("projectId");
	}
	var id = location.href.split('?')[1];
	//console.log(id)
	var detailTpl= Handlebars.compile(detailHtml);
	var detailProject = function(){
		$.get("/lt/project/getProjDetail?id=" + id,function(data){
			if(!data.result){

				$(".project_find_search_box_title").html(detailTpl(data));
			}
		});
	};
	detailProject();

	//信息
	var infoHtml = $("#detail_project_info").html();
	//alert(detailHtml)
	var infoTpl= Handlebars.compile(infoHtml);
	var infoProject = function(){
//console.log(projectId);
		$.get("/lt/project/getProjDetail?id=" + id,function(data){
			if(!data.result){
				if(data.data.phase == "1") {
					data.data.phase="A轮";
				} else if(data.data.phase == "2") {
					data.data.phase="B轮";
				} else if(data.data.phase == "3") {
					data.data.phase="C轮";
				}
				$(".project_find_info_box").html(infoTpl(data));
				phone();
			}
		});
	};
	infoProject();
	var phone=function(){
		$(".project_find_info_box_left_cont").live("click",function(){
			$(this).find("a").hide();
			$(this).find("em").show();
		})
	}
	//项目简介
	var proHtml = $("#detail_project_jj").html();
	//alert(detailHtml)
	var proTpl= Handlebars.compile(proHtml);
	var summaryProject = function(){
		$.get("/lt/project/getProjDetail?id=" + id,function(data){
			//console.log(data)
			if(!data.result){
				$(".project_find_comp_box").html(proTpl(data));
			}
		});
	};
	summaryProject();
	//成员介绍
	var introHtml = $("#detail_member_intro").html();

	//alert(detailHtml)
	var introTpl= Handlebars.compile(introHtml);
	var introProject = function(){
		//console.log(introHtml)
		$.get("/lt/user/getProjDetail?id=" + id,function(data){
			//console.log(data.memberIntro);
			if(!data.result){
				if(data.data.memberIntro) {
					data.data.memberIntro = JSON.parse(data.data.memberIntro);
				}
				
				
				$(".project_team_history").html(introTpl(data.data));
				var _length=0;
				var _text=$(".project_team_history_box");

				//console.log(_length)
				for(_length=1;_length<=_text.length;_length++){
					(function(i){
						var aNum = ["零","一","二","三","四","五","六","七","八","九","十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十"];
						var text;
						console.log(_length)
						$(".project_team_history_left").eq(i-1).html("<span>成员"+aNum[i]+"</span>")
					})(_length)
				}


				//console.log(1);
			}

		});
	};
	introProject();
	//市场分析
	var scHtml = $("#project_sc_history").html();
	//alert(detailHtml)
	var scTpl= Handlebars.compile(scHtml);
	var scProject = function(){
		$.get("/lt/project/getProjDetail/?id=" + id,function(data){
			if(!data.result){
				$(".project_sc_history").html(scTpl(data));
			}
		});
	};
	scProject();

	//竞争对手分析
	var dsHtml = $("#project_ds_history").html();
	//alert(detailHtml)
	var dsTpl= Handlebars.compile(dsHtml);
	var dsProject = function(){
		$.get("/lt/project/getProjDetail/?id=" + id,function(data){
			if(!data.result){
				$(".project_ds_history").html(dsTpl(data));
			}
		});
	};
	dsProject();

	//资金用途
	var zjHtml = $("#project_zj_history").html();
	//alert(detailHtml)
	var zjTpl= Handlebars.compile(zjHtml);
	var zjProject = function(){
		$.get("/lt/project/getProjDetail/?id=" + id,function(data){
			if(!data.result){
				$(".project_zj_history").html(zjTpl(data));
			}
		});
	};
	zjProject();



	//项目评论
	var plHtml = $("#project_pl_history").html();
	//alert(detailHtml)
	var plTpl= Handlebars.compile(plHtml);
	var plProject = function(){
		$.get("/lt/project/getProjDetail/?id=" + id,function(data){
			if(!data.result){
				$(".project_pl_history").html(plTpl(data));
			}
		});
	};
	plProject();
	//项目评论
	var pl1Html = $("#project_pl1_history").html();
	//alert(detailHtml)
	var pl1Tpl= Handlebars.compile(pl1Html);
	var pl1Project = function(){
		$.get("/lt/project/getProjDetail/?id=" + id,function(data){
			if(!data.result){
				$(".project_pl1_history").html(pl1Tpl(data));
			}
		});
	};
	pl1Project();


})(jQuery);